﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DEMO3.GUI
{
    public partial class VeBan : UserControl
    {
        public VeBan()
        {
            InitializeComponent();
        }

        private void btBanVe_Click(object sender, EventArgs e)
        {
            if (gv.GetRowCellValue(gv.FocusedRowHandle, "LoaiVe").ToString() == "1")
                return;
            string manv = "1";
            DataProvider test = new DataProvider();
            SqlParameter[] arrpara = new SqlParameter[2];
            arrpara[0] = new SqlParameter("mave", gv.GetRowCellValue(gv.FocusedRowHandle, "MaVe").ToString());
            arrpara[1] = new SqlParameter("manv",   manv);
            test.ExcuteNonQuery("BAN_VE",arrpara);
            LoadData();
        }

        private void VEBAN_Load(object sender, EventArgs e)
        {
            DataProvider test = new DataProvider();
            if (!test.OpenConnect())
                Main.Warning();
            else
                LoadData();
            test.CloseConnect();
        }
        private void LoadData()
        {
            DataProvider test = new DataProvider();
            cbxTV.DataSource = test.ExcuteQuery("GET_THANHVIEN", null);
            cbxTV.DisplayMember = "TenThanhVien";
            cbxTV.ValueMember = "MaThanhVien";

            gc.DataSource = test.ExcuteQuery("GET_VE", null);
        }

        private void gv_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gv.FocusedRowHandle != gv.RowCount && gv.RowCount!=0)
            {
                txtMaVe.Text = gv.GetRowCellValue(gv.FocusedRowHandle, "MaVe").ToString();
                cbxTV.SelectedValue = gv.GetRowCellValue(gv.FocusedRowHandle, "MaThanhVien").ToString();
                if ((bool)gv.GetRowCellValue(gv.FocusedRowHandle, "LoaiVe") == true)
                {
                    txtTrangThai.Text = "VÉ ĐÃ BÁN";
                    btBanVe.Enabled = false;
                }
                else
                {
                    txtTrangThai.Text = "VÉ ĐANG ĐẶT";
                    btBanVe.Enabled = true;
                }
            }
        }
    }
}
